CSharpTest.Net
CacheKeepAliveTimeout Property
See Also  Example Send Feedback Download Help File
CSharpTest.Net.BPlusTree Assembly > CSharpTest.Net.Collections Namespace > BPlusTreeOptions<TKey,TValue> Class : CacheKeepAliveTimeout Property

Glossary Item Box

If the cache contains more that CacheKeepAliveMinimumHistory items, this timeout will start to remove those items until the cache history is reduced to CacheKeepAliveMinimumHistory. It is important to know that the BPlusTree itself contains no theads and this timeout will not be respected if cache is not in use.

Syntax

Visual Basic (Declaration) 
Public Property CacheKeepAliveTimeout As Integer
C# 
public int CacheKeepAliveTimeout {get; set;}

Example

BPlusTree/BPlusTree.Test/ThreadedBTreeTest.cs

C#Copy Code
BPlusTree<KeyInfo, DataValue>.OptionsV2 options = new BPlusTree<KeyInfo, DataValue>.OptionsV2(
    new KeyInfoSerializer(), new DataValueSerializer(), new KeyInfoComparer());
            
const int keysize = 16 + 4;
const int valuesize = keysize + 256 + 44;

options.CalcBTreeOrder(keysize, valuesize); 
options.FileName = TempFile.TempPath;
options.CreateFile = CreatePolicy.Always;
options.FileBlockSize = 8192;
options.StorageType = StorageType.Disk;
            
options.CacheKeepAliveTimeout = 10000;
options.CacheKeepAliveMinimumHistory = 0;
options.CacheKeepAliveMaximumHistory = 200;
            
options.CallLevelLock = new ReaderWriterLocking();
options.LockingFactory = new LockFactory<SimpleReadWriteLocking>();
options.LockTimeout = 10000;

using(BPlusTree<KeyInfo, DataValue> dictionary = new BPlusTree<KeyInfo, DataValue>(options))
using(WorkQueue work = new WorkQueue(Environment.ProcessorCount))
{
    Exception lastError = null;
    work.OnError += delegate(object o, ErrorEventArgs e) { lastError = e.GetException(); };

    for (int i = 0; i < Environment.ProcessorCount; i++)
        work.Enqueue(new ThreadedTest(dictionary, 1000).Run);

    Assert.IsTrue(work.Complete(true, 60000));
    Assert.IsNull(lastError, "Exception raised in worker: {0}", lastError);
}
VB.NETCopy Code
Dim options As New BPlusTree(Of KeyInfo, DataValue).OptionsV2(New KeyInfoSerializer(), New DataValueSerializer(), New KeyInfoComparer())

Const  keysize As Integer = 16 + 4
Const  valuesize As Integer = keysize + 256 + 44

options.CalcBTreeOrder(keysize, valuesize)
options.FileName = TempFile.TempPath
options.CreateFile = CreatePolicy.Always
options.FileBlockSize = 8192
options.StorageType = StorageType.Disk

options.CacheKeepAliveTimeout = 10000
options.CacheKeepAliveMinimumHistory = 0
options.CacheKeepAliveMaximumHistory = 200

options.CallLevelLock = New ReaderWriterLocking()
options.LockingFactory = New LockFactory(Of SimpleReadWriteLocking)()
options.LockTimeout = 10000

Using dictionary As New BPlusTree(Of KeyInfo, DataValue)(options)
    Using work As New WorkQueue(Environment.ProcessorCount)
        Dim lastError As Exception = Nothing
        work.OnError += Function(o As Object, e As ErrorEventArgs) Do
            lastError = e.GetException()
        End Function

        Dim i As Integer = 0
        While i < Environment.ProcessorCount
            work.Enqueue(New ThreadedTest(dictionary, 1000).Run)
            System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
        End While

        Assert.IsTrue(work.Complete(True, 60000))
        Assert.IsNull(lastError, "Exception raised in worker: {0}", lastError)
    End Using
End Using

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys